<template>
	<div>
    <el-input v-model="treeTS.filterText.value" placeholder="关键字" />

    <el-tree 
      class="tree-line"
      v-loading="treeTS.tableDataLoading.value"
      accordion
      style="margin-top: 5px;"
      ref="userTree"
      :data="treeTS.tableData.value" 
      :props="treeTS.defaultProps.value" 
      @node-click="treeTS.handleNodeClick"
      node-key="id"
      :default-expanded-keys="treeTS.expandedData.value"
      highlight-current
      :filter-node-method="treeTS.filterNode"
     >
      <template #default="{ node, data }">
        <!-- <div>
          <i :class="`icon element-icons ${data.icon}`"></i>
          <span style="margin-left: 5px;">{{node.label}}</span>
        </div> -->
        <span class="custom-tree-node">
          <span>{{ node.label }}</span>
          <span>

            <!-- -1 -组/根 0/1 设备  -->
            <el-button type="success" size="mini" @click.stop="dialogTS.addDevice(data)" v-if="data.protocol == -1 || data.id == 0">新增</el-button>
            <el-button type="primary" size="mini" @click.stop="dialogTS.detailDevice(data)" v-if="data.protocol != -1 && data.id != 0">详情</el-button>
            <el-button type="primary" size="mini" @click.stop="dialogTS.editDevice(data)" v-if="data.id != 0">设置</el-button>
            <el-button type="danger" size="mini" @click.stop="dialogTS.deleteDevice(data)" v-if="data.id != 0">删除</el-button>
          </span>
        </span>
      </template>

    </el-tree>

    <el-dialog v-model="dialogTS.show.value" :title="dialogTS.title.value">
      <div v-if="dialogTS.status.value != 2">
        <el-form :model="dialogTS.form.value">
          <el-form-item label="名称" label-width="120">
            <el-input v-model="dialogTS.form.value.name" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="类型" label-width="120" v-if="dialogTS.status.value == 0">
            <el-select v-model="dialogTS.form.value.type" placeholder="">
              <el-option
                v-for="item in System.$store.text.treeOP"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="父级" label-width="120">

            <el-select style="width: 100%;" v-model="dialogTS.form.value.pid" filterable placeholder="Select">
              <el-option
                v-for="item in treeTS.chooseList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>

          </el-form-item>
        </el-form>
      </div>

      <div v-if="dialogTS.status.value == 2">
        是否要删除 {{dialogTS.form.value.name}} ?
      </div>

      <template #footer>
        <span class="dialog-footer">
          <el-button @click="dialogTS.show.value = false">取消</el-button>
          <el-button type="primary" @click="dialogTS.submit"
            >确定</el-button
          >
        </span>
      </template>
    </el-dialog>

  </div>
</template>
<script setup lang="ts">

import { Tree } from 'element-plus/es/components/tree-v2/src/types';
import { ref,Ref } from 'vue';

import System from '~/utils/System';

import VueTreeMain from './VueTreeMain';
let treeTS = new VueTreeMain()

import VueTreeDialog from './VueTreeDialog';
import CEvent from '~/utils/CEvent';
import { log } from 'console'
let dialogTS = new VueTreeDialog()

let userTree:Ref<Tree | null> = ref(null)
System.$refs['userTree'] = userTree

</script>
<style lang="less" scoped>

  @import "~/assets/less/treeLine.less";

</style>
